package com.yifi.system.controller;

import java.util.List;

import com.jfinal.core.Path;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.yifi.common.SysUtil;
import com.yifi.common.base.BaseController;
import com.yifi.common.utils.StringUtils;
import com.yifi.common.utils.ToolString;

@Path(value="/syslog",viewPath = "/")
public class SysLogController extends BaseController {

	public void index()
	{
		render("system/syslog.html");
	}
	
	public void getStatus()
	{
		String sql="select distinct status as ccode,status as cname from pt_syslog ";
		List<Record> list=SysUtil.getListDDL(sql, "cname", "ccode");
		renderJson(list);
	}
	
	public void list()
	{
		String status=getPara("status","all");
		String description=getPara("description","");
		String sqlSelect="select * ";
		String sqlExcept=" from pt_syslog where 1=1 ";
		if(!status.equals("all"))
		{
			sqlExcept+=" and status='"+status+"' ";
		}
		if(StringUtils.isNotEmpty(description))
		{
			sqlExcept+=" and description like '%"+description+"%' ";
		}
		
		sqlExcept+=" order by enddate desc";
		renderJson(getDataTable(sqlSelect, sqlExcept));
	}

	public void remove()
	{
		String ids=getPara("ids","");
		ids=ToolString.getIdsToStr(ids);
		String sql="delete from pt_syslog where id in ("+ids+")";
		if(Db.update(sql)>0)
		{
			renderJson(success("删除成功！"));
		}
		else
		{
			renderJson(error("删除失败！"));
		}
	}
	public void removeAll()
	{
		String status=getPara("status","all");
		String sql="delete from pt_syslog where status='"+status+"'";
		if(Db.update(sql)>0)
		{
			renderJson(success("删除成功！"));
		}
		else
		{
			renderJson(error("删除失败！"));
		}
	}
	
	public void export()
	{
		
	}
}
